using System.Data;
using System.Data.Common;
using EFProviderWrapperToolkit;

namespace EFMetaProvider
{
    public sealed class EFMetaCommand : DbCommandWrapper
    {
    	public EFMetaCommand(DbCommand wrappedCommand, DbCommandDefinitionWrapper commandDefinition)
            : base(wrappedCommand, commandDefinition)
        {
        }

        public override int ExecuteNonQuery()
        {
        	return WrappedCommand.ExecuteNonQuery();
        }

        public override object ExecuteScalar()
        {
        	return WrappedCommand.ExecuteScalar();
        }

        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
        	var reader = WrappedCommand.ExecuteReader(behavior);
        	((EFMetaConnection)Connection).SchemaTable = reader.GetSchemaTable();
        	return reader;
        }
    }
}
